<template>
    <el-button type="primary" round @click="UpdManpower">保存</el-button>

    <el-form :model="form" label-width="auto" style="max-width: 600px">
        <el-form-item label="档案编号">
            <el-input v-model="form.mNumber" placeholder="保存后自动生成" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="真实姓名">
            <el-input v-model="form.mName" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="性别">
            <el-radio-group v-model="form.mSex">
                <el-radio :value="true">男</el-radio>
                <el-radio :value="false">女</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="出生日期" style="width: 300px;">
            <el-date-picker v-model="form.mBirthDay" type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                style="width: 100%" />
        </el-form-item>
        <el-form-item label="身份证号码">
            <el-input v-model="form.mIdCard" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="联系电话">
            <el-input v-model="form.mPhone" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="电子邮箱">
            <el-input v-model="form.mEmail" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="微信号">
            <el-input v-model="form.mWeChat" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="QQ号">
            <el-input v-model="form.mqq" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="紧急联系人">
            <el-input v-model="form.mContact" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="紧急联系人电话">
            <el-input v-model="form.mcPhone" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="户口地址">
            <el-input v-model="form.mPermanent" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="家庭住址">
            <el-input v-model="form.mResidence" />
        </el-form-item>
        <el-form-item label="入职时间" style="width: 300px;">
            <el-date-picker v-model="form.mEntryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                style="width: 100%" />
        </el-form-item>
        <el-form-item label="所在部门">
            <el-select v-model="form.sectorId" placeholder="请选择部门" style="width: 200px;">
                <el-option v-for="item in sectorlist" :key="item.value" :label="item.label" :value="item.value"
                    @click="GetPostList()" />
            </el-select>
        </el-form-item>
        <el-form-item label="所在岗位">
            <el-select v-model="form.postId" placeholder="请选择岗位" style="width: 200px;">
                <el-option v-for="item in postlist" :key="item.postId" :label="item.postName" :value="item.postId" />
            </el-select>
        </el-form-item>
    </el-form>
</template>

<script setup lang='ts'>
import axios from 'axios'
import { ElMessage } from 'element-plus';
import { ref, reactive, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
import http from '../../http.js'

//修改
const form = reactive({
    "manpowerId": "",
    "postId": "",
    "sectorId": "",
    "mNumber": "",
    "mName": "",
    "mSex": true,
    "mBirthDay": "",
    "mIdCard": "",
    "mPhone": "",
    "mEmail": "",
    "mWeChat": "",
    "mqq": "",
    "mContact": "",
    "mcPhone": "",
    "mPermanent": "",
    "mResidence": "",
    "mIdPhoto": "",
    "mEntryDate": "",
})

onMounted(() => {
    FanManpowerList();
    GetSectorList();
})

//部门
const sectorlist = ref([])
const GetSectorList = () => {
    axios.get(http.zblnb + '/vendor/api/Post/GetSectorList')
        .then(res => {
            sectorlist.value = res.data.data;
        })
}

//岗位
const postlist = ref([])
const GetPostList = () => {
    form.postId = "";
    axios.get(http.zblnb + '/vendor/api/Post/GetPostList?SectorId=' + (form.sectorId || 0))
        .then(res => {
            postlist.value = res.data.data;
        })
}

//反填
const FanManpowerList = () => {
    axios.get(http.zblnb + '/vendor/api/Manpower/FanManpower?ManpowerId=' + route.query.manpowerId)
        .then(res => {
            let d = res.data.data[0];
            form.mNumber = d.mNumber;
            form.mName = d.mName;
            form.mSex = d.mSex;
            form.mBirthDay = d.mBirthDay;
            form.mIdCard = d.mIdCard;
            form.mPhone = d.mPhone;
            form.mEmail = d.mEmail;
            form.mWeChat = d.mWeChat;
            form.mqq = d.mqq;
            form.mContact = d.mContact;
            form.mcPhone = d.mcPhone;
            form.mPermanent = d.mPermanent;
            form.mResidence = d.mResidence;
            form.mIdPhoto = d.mIdPhoto;
            form.mEntryDate = d.mEntryDate;
            form.sectorId = d.sectorId;
            GetPostList();
            form.postId = d.postId;
            form.manpowerId = route.query.manpowerId;
        })
}


//修改人员档案
const UpdManpower = () => {
    axios.post(http.zblnb + '/vendor/api/Manpower/UpdManpower', form)
        .then(res => {
            if (res.data != 0) {
                ElMessage.success('修改成功');
                router.push('/ListManpower')
            }
            else {
                ElMessage.error('修改失败');
            }
        })
}


</script>

<style></style>